Change the background-image

This script will change the background image of a element of your choice in you webpage. Be sure to adjust the id in line 29 corresponding to the element as described in line 50.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Change Background</title>

<style type="text/css">

body {
background-color: black;
}

p {
color: white;
font-family: arial, sans-serif;
font-size: 24px;
margin: 0px;
}

#bgc {
padding: 6px;
border: 1px red solid;
width: 500px; height: 300px;
}

</style>

<script type="text/javascript">

function slide()
{
document.getElementById("bgc").style.background = '#111 url(' + picture[ch] + ') top right no-repeat';
if(ch == sumpics)
{ ch = 0; }
else
{ ch++; }
changement = 6; //Time in sec.
window.setTimeout("slide()", (changement*1000));
}

picture = new Array()
picture[0] = '\'06316_116.jpg\'';
picture[1] = '\'NGM1998_01p114-5.jpg\'';
picture[2] = '\'wallpaper_lg.1.1(20).jpg\'';

sumpics = picture.length-1;
ch = 0;
</script>

</head>
<body onload="slide()">

<div id="bgc">
<p>This is a test to change your background with javascript.</p>
</div><!-- Einde div background test -->

</body>
</html>

Example: